package com.tfswx.ruleengine.fn;

import com.alibaba.fastjson.JSON;
import com.greenpineyu.fel.context.FelContext;
import com.tfswx.ruleengine.compute.gzjy.BaseFn;
import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * @author ricky
 * @date 2021/8/16
 */
public class Join extends BaseFn {

    @Override
    public Object call(Object[] arguments, FelContext context) {
        String listStr = String.valueOf(arguments[0]);
        String separator = String.valueOf(arguments[1]);
        List<Object> objects = JSON.parseArray(listStr).toJavaList(Object.class);
        return StringUtils.join(objects, separator);
    }

    @Override
    public String getZwmc() {
        return "数组转字符串";
    }


    @Override
    public List<Param> getParams() {
        List<Param> params = new ArrayList<>();
        params.add(new Param("listStr"));
        params.add(new Param("separator"));
        return params;
    }


    @Override
    public String getName() {
        return "join";
    }
}
